﻿using System;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Sustainalytics.Utils.WebApi.ErrorCodes;
using System.Web.Http.Cors;
using Sustainalytics.Controversies.Service.BlInvoker;

namespace Sustainalytics.Controversies.Service.Controllers
{
    [EnableCors(origins: "*", headers: "*", methods: "*")]
    //[ClaimsChecker("api/v1/company/controversies")]
    [RoutePrefix("api/v1/company")]
    public class EventIndicatorController:ApiController
    {
        private readonly IServiceBlInvoker _blInvoker;
        public EventIndicatorController(IServiceBlInvoker blInvoker)
        {
            _blInvoker = blInvoker;
        }


        [Route("{companyId}/controversyIndicator/{controversyIndicatorId}/eventIndicator")]
        public HttpResponseMessage Get(Guid companyId, Guid controversyIndicatorId)
        {
            try
            {
                return Request.CreateResponse(HttpStatusCode.OK,
                    _blInvoker.GetEventIndicatorsFromControversy(companyId, controversyIndicatorId));
            }
            catch (Exception)
            {

                return Request.CreateResponse(HttpStatusCode.InternalServerError,
                    new { ErrorStatusCode = WebAPIGeneralErrorCodes.UnhandledException });
            }
        }

        [Route("{companyId}/controversyIndicator/{controversyIndicatorId}/eventIndicator/{eventIndicatorId}")]
        public HttpResponseMessage Get(Guid companyId, Guid controversyIndicatorId, Guid eventIndicatorId, [FromUri] bool includeAllFields = false)
        {
            try
            {
                return Request.CreateResponse(HttpStatusCode.OK,
                    _blInvoker.GetEventIndicatorDetailData(companyId, controversyIndicatorId, eventIndicatorId, includeAllFields));
            }
            catch (Exception)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError,
                    new { ErrorStatusCode = WebAPIGeneralErrorCodes.UnhandledException });
                
            }
        }

    }
}
